import { log } from "cc";
import { Loger } from "../loger/Loger";

export class Stack<T>{
    private items = null;
    constructor() {
        this.items = new Array<T>();
    }

    push(data: T): void {
        this.items.push(data);
    }

    pop(): T {
        return this.items.pop();
    }

    top(): T {
        return this.items[this.items.length - 1];
    }

    get(idx:number){
        return this.items[idx];
    }

    isEmpty(): boolean {
        return this.items.length === 0;
    }

    size(): number {
        return this.items.length;
    }

    clear(): void {
        this.items = new Array<T>();
    }

    print(): void {
        log(this.items);
        Loger.log(JSON.stringify(this.items));
    }
}
